"use strict";
cc._RF.push(module, '702b4VeEuJMopDUi3UTXF+F', 'Drag');
// scripts/modes/normalMode/baseScript/Drag.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var DragBase = /** @class */ (function (_super) {
    __extends(DragBase, _super);
    function DragBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prePos = null;
        _this.isInArea = false;
        _this.targetPos = null;
        _this.speakLabelPref = null;
        _this.speakLabel = null;
        _this.canMove = true;
        // update (dt) {}
        _this.isSpeak = false;
        return _this;
    }
    DragBase.prototype.setPrePos = function (pos) {
        this.prePos = pos;
    };
    DragBase.prototype.setIsInArea = function (bool) {
        this.isInArea = bool;
    };
    DragBase.prototype.setTargetPos = function (pos) {
        this.targetPos = pos;
    };
    DragBase.prototype.setCanMove = function (bool) {
        this.canMove = bool;
    };
    DragBase.prototype.onLoad = function () {
    };
    DragBase.prototype.start = function () {
        this.node.on(cc.Node.EventType.TOUCH_START, this.moveComponentStart.bind(this));
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.moveComponent.bind(this));
        this.node.on(cc.Node.EventType.TOUCH_END, this.moveComponentEnd.bind(this));
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.moveComponentEnd.bind(this));
    };
    DragBase.prototype.speak = function (word) {
        var _this = this;
        if (this.isSpeak && this.speakLabel) {
            this.speakLabel.removeFromParent();
            this.speakLabel = null;
        }
        this.isSpeak = true;
        this.speakLabel = cc.instantiate(this.speakLabelPref);
        this.node.addChild(this.speakLabel);
        this.speakLabel.getComponent(cc.Label).string = word;
        cc.tween(this.speakLabel).to(0.2, { opacity: 255 }).delay(2).to(0.2, { opacity: 0 }).call(function () {
            _this.isSpeak = false;
            _this.speakLabel.removeFromParent();
            _this.speakLabel = null;
        }).start();
    };
    DragBase.prototype.goTargetPos = function () {
        cc.tween(this.node).to(0.1, { x: this.targetPos.x, y: this.targetPos.y }).start();
        this.node.off(cc.Node.EventType.TOUCH_START);
        this.node.off(cc.Node.EventType.TOUCH_MOVE);
        this.node.off(cc.Node.EventType.TOUCH_END);
        this.node.off(cc.Node.EventType.TOUCH_CANCEL);
    };
    DragBase.prototype.goPrePos = function () {
        cc.tween(this.node).to(0.1, { x: this.prePos.x, y: this.prePos.y }).start();
    };
    DragBase.prototype.moveComponentStart = function (touchEvent) {
        if (!this.canMove)
            return;
    };
    DragBase.prototype.moveComponent = function (touchEvent) {
        if (!this.canMove)
            return;
        var touchPos = touchEvent.getLocation();
        var nextPos = this.node.parent.convertToNodeSpaceAR(touchPos);
        this.node.setPosition(nextPos);
    };
    DragBase.prototype.moveComponentEnd = function (touchEvent) {
        if (!this.canMove)
            return;
        if (!this.isInArea && this.prePos != null) {
            cc.tween(this.node).to(0.2, { x: this.prePos.x, y: this.prePos.y }).start();
        }
        else if (this.isInArea) {
            this.goTargetPos();
        }
    };
    DragBase.prototype.onCollisionEnter = function (other, self) {
    };
    DragBase.prototype.onCollisionStay = function (other, self) {
    };
    DragBase.prototype.onCollisionExit = function (other, self) {
    };
    __decorate([
        property({ type: cc.Prefab, displayName: "说话预制体" })
    ], DragBase.prototype, "speakLabelPref", void 0);
    DragBase = __decorate([
        ccclass
    ], DragBase);
    return DragBase;
}(cc.Component));
exports.default = DragBase;

cc._RF.pop();